<!DOCTYPE html>
<#assign base=request.contextPath />
<html lang="en">
<head>
    <base id="base" href="${base}">
    <meta charset="UTF-8">
    <title>服务前端</title>
</head>
<body>
<div align="center">
    <table>
        <tr>
            <td rowspan="8"><img src="${productVo.imageUrl}"></td>
            <input type="hidden" id="productId" value="${productVo.productId }">
        </tr>
        <tr>
            <td>${productVo.productName}</td>
        </tr>
        <tr>
            <td>价格：￥${productVo.price}/${productVo.unit}</td>
        </tr>
        <tr>
            <td>分类：${productVo.categoryName}</td>
        </tr>
        <tr>
            <td>商家：${productVo.busTeamName}</td>
        </tr>
        <tr>
            <td>销量：${productVo.amount}    累计评价：${amount}</td>
        </tr>
        <tr>
            <td><button id="add">+</button><input name="quantity" value="1" id="quantity"><button id="sub">-</button></td>
        </tr>
        <tr>
            <td><button id="buyNow">立即购买</button><button id="addToCart">加入购物车</button></td>
        </tr>
    </table>
</div>
<div align="center">
    <label>商品介绍</label>
    ${productVo.content}
</div><br>
<div align="center">
    <label>评价</label>
    <#list commentList as comment>
        <div>${comment.createTime?string("yyyy-MM-dd")}</div>
        <div>${comment.comment}</div><br>
    </#list>
</div>

</body>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>
<script>
    $(function () {
        var base = $("#base").attr("href");
        var quantity = $("#quantity").val();
        $("#add").click(function () {
            quantity++;
            $("#quantity").val(quantity);
        })
        $("#sub").click(function () {
            if(quantity != 1) {
                quantity--;
                $("#quantity").val(quantity);
            }
        })
        $("#addToCart").click(function () {
            var quantity = $("#quantity").val();
            var productId = $("#productId").val();
            $.ajax({
                url:base+"/trading/product/addProductToCart",
                type:"POST",
                data:{productId:productId, quantity:quantity, type:0},
                success:function (data) {
                    if(data == "ok"){
                        window.location.href = base+"/trading/product/showCartItems?type=0";
                    }
                }
            })
        })
        $("#buyNow").click(function () {
            var quantity = $("#quantity").val();
            var productId = $("#productId").val();
            window.location.href = base+"/trading/product/buyNow?productId="+productId+"&quantity="+quantity;
        })
    })
</script>
</html>